<template>
  <div class="dashboard-editor-container">
    <el-card>
      <el-form :model="form" size="mini" label-position="top" ref="form">
        <el-row :gutter="10">
          <el-col :lg="5" :md="6">
            <el-form-item label="案例编号" prop="CASENO">
              <el-input size="small" placeholder="请输入案例编号" v-model="form.CASENO"></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="5" :md="6">
            <el-form-item label="坐席ID" prop="AGENTID">
              <el-input size="small" placeholder="请输入案例编号" v-model="form.AGENTID"></el-input>
            </el-form-item>
          </el-col>
          <el-col :lg="4" :md="6">
            <el-form-item label="学习状态" prop="STATUS">
              <el-select v-model="form.STATUS" filterable clearable placeholder="请选择学习状态">
                <el-option v-for="(item,index) in studyStatusOption" :key="index" :label="item.val" :value="item.code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="6" :md="10" class="searchBtnMarginTop">
            <el-button
              type="primary"
              icon="el-icon-search"
              :loading="loading"
              size="mini"
              @click="queryCaseStudyTask('form')"
            >查询</el-button>
            <el-button
              type="warning"
              size="mini"
              icon="el-icon-refresh"
              @click="clearForm('form')"
            >重置</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table :data="tableData" border highlight-current-row class="tableMarginTop">
        <el-table-column prop="TASKSERINO" align="center" label="学习任务序号"></el-table-column>
        <el-table-column prop="CASENO" align="center" label="案例编号"></el-table-column>
        <el-table-column prop="TASKBEGINDATE" align="center" width="110" label="任务开始日期"></el-table-column>
        <el-table-column prop="TASKENDDATE" align="center"  width="110" label="任务结束日期"></el-table-column>
        <el-table-column prop="AGENTID" align="center" width="100" label="坐席ID"></el-table-column>
        <el-table-column prop="AGENTNAME" align="center" label="坐席姓名"></el-table-column>
        <el-table-column prop="STUDYBEGINDATE" align="center" label="学习开始日期"></el-table-column>
        <el-table-column prop="STUDYENDDATE" align="center" label="学习结束日期"></el-table-column>
        <el-table-column prop="ALLOCATER" align="center" label="任务分配人员"></el-table-column>
        <el-table-column prop="FILEPATH" align="center" label="文件路径"></el-table-column>
        <el-table-column prop="FILENAME" align="center" label="文件名称"></el-table-column>
        <el-table-column prop="FILETYPE" align="center" label="文件格式"></el-table-column>
        <el-table-column prop="STATUS" align="center" label="学习状态" :formatter="dataFormat"></el-table-column>
        <el-table-column label="操作" align="center"  fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                type="success"
                size="mini"
                @click="study(scope.row)"
                v-if="scope.row.STATUS == '0'"
              >学习</el-button>
              <el-button
                type="success"
                size="mini"
                @click="study(scope.row)"
                v-if="scope.row.STATUS == '1'"
              >完成学习</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <el-col>
          <el-pagination
            style="text-align: right; margin-top:20px;"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            @size-change="handleInSizeChange"
            @current-change="handleInCurrentChange"
            :current-page="currpage"
            background
            layout="total,sizes, prev, pager, next, jumper"
            :total="tableTotal"
          ></el-pagination>
        </el-col>
      </el-row>
    </el-card>
    <!-- <component :is="dialogList.studyDialog" :option="studyOptions" @refreshTable="queryCaseStudyTask"></component> -->
  </div>
</template>
<script>
import getGlobalParams from "@/common/utils/getGlobalParams";
import request from "@/common/utils/requestQC";
import toolBox from "@/common/utils/toolBox";
// import studyDialog from "./dialog/studyDialog";
import caseTaskQuery from "@/message/QCManage/caseManage/caseTaskQuery";
import requestWFM from "@/common/utils/requestWFM";
export default {
  data() {
    return {
      creatTypeOption: [{ 'code': "0", 'val': "手动导入" }, {'code': "1", 'val': "质检关联"}],
      caseStatusOption: [{ 'code': "0", 'val': "通过" }, { 'code': "1", 'val': "申请" }, { 'code': "2", 'val': "不通过" }],
      fileTypeOption:[{ 'code': "video", 'val': "视频" },{ 'code': "voice", 'val': "语音" },{ 'code': "chat", 'val': "文字" }],
      caseTypeOption: [{ 'code': "0", 'val': "成功案例" }, {'code': "1", 'val': "失败案例"}],
      operaflagOption:[{ 'code': "0", 'val': "已通过" }, {'code': "2", 'val': "删除"}],
      studyStatusOption:[{ 'code': "0", 'val': "未学习" }, {'code': "2", 'val': "已学习"},{ 'code': "1", 'val': "学习中" }],
      // dialogList: {
      //   studyDialog
      // },
      studyOptions: {
        isShow: false,
        title: "",
        row: {}
      },
      tableTotal: 1,
      currpage: 1,
      pageSize: getGlobalParams.get("PageSize"),
      tableData: [],
      form: {
        CASENO: "",
        AGENTID: "",
        STATUS: ""
      },
      loading: false
    };
  },
  mounted() {
    this.queryCaseStudyTask();
  },
  methods: {
    async queryCaseStudyTask(row) {
      let resBody = new caseTaskQuery();
      resBody.data.CASENO = this.form.CASENO;
      resBody.data.AGENTID = this.form.AGENTID;
      resBody.data.STATUS = this.form.STATUS;
      resBody.data.PageFlag = 4;
      resBody.data.CurrPage = this.currpage;
      resBody.data.PageRowNum = this.pageSize;
      let response = await request(resBody);
      if (response.SYS_HEAD.ReturnCode == "000000") {
        this.tableData = response.BODY.RSPSTRUCT;
        this.tableTotal = response.BODY.TotalRowNum;
        // this.currpage = response.BODY.NowPageNum;
      } else {
        this.$message({
          type: "error",
          message:
            "请求失败，错误码:" +
            response.SYS_HEAD.ReturnCode +
            "，错误信息：" +
            response.SYS_HEAD.ReturnMessage
        });
      }
    },
    // 学习
    async study(row) {
      this.$router.push({
                name: 'caseStudy',
                params: {
                  title: '学习',
                  row:row
                }
              });
      
    },


   
    dataFormat(row, column) {
      if(column.property == "STATUS")
        return row[column.property] == '0'?'未学习':row[column.property] == '2'?'已学习':row[column.property] == '1'?'学习中':row[column.property]
    },
    findCode(arr, val) {
      let data = arr.filter(item => {
        return item.TRANSCODE == val;
      });
      if (data.length) return data[0].TRANSCODE + " - " + data[0].TRANSNAME;
    },
    findName(arr, val) {
      let data = arr.filter(item => {
        return item.FIELDKEY == val;
      });
      if (data.length) return data[0].FIELDKEY + " - " + data[0].FIELDVALUE;
    },
    findTemplate(arr, val) {
      let data = arr.filter(item => {
        return item.SCORETEMPLATEID == val;
      });
      if (data.length)
        return data[0].SCORETEMPLATEID + " - " + data[0].SCORETEMPLATENAME;
    },
    //前端分页
    handleInCurrentChange(val) {
      this.currpage = val;
      // console.log(`当前页: ${val}`);
      this.queryCaseStudyTask();
    },
    handleInSizeChange(val) {
      this.pageSize = val;
      this.queryCaseStudyTask();
    },
    // 重置查询条件
    clearForm(item) {
      // 重置表格
      this.$refs["" + item].resetFields();
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>